package com.silverhaze.diamond.client.ui.table.model;

import com.silverhaze.diamond.common.entity.Detail;
import com.silverhaze.diamond.client.ui.UIStringConstants;

import java.util.List;

/**
 * Author: Ivan Babanin
 * Time: 16:35:13
 * Date: 22.05.2008
 * <p/>
 * This part of code is strictly confidential.
 */
public class SimilarDetailsTableModel extends AbstractServiceTableModel<Detail> {
    private List<Detail> data;
    private static int colCount = 3;

    public SimilarDetailsTableModel(List data) {
        super(data);
    }

    public void refreshModelAll() {
    }

    public Detail getObjectAtRow(int row) {
        return data.get(row);
    }

    public void fillData(List data) {
        this.data = data;

        setData(new Object[colCount][data.size()]);

        Object[][] dataObjects = getData();
        for (int i = 0; i < data.size(); i++) {
            dataObjects[0][i] = this.data.get(i).getId();
            dataObjects[1][i] = this.data.get(i).getName();
            dataObjects[2][i] = this.data.get(i).getDescription();
        }
    }

    protected void createFields() {
        setColCountSize(colCount);
        setColumnName(new String[]{
                UIStringConstants.ID,
                UIStringConstants.DETAIL,
                UIStringConstants.DESCRIPTION
        });
    }

    public int getRowCount() {
        if (getData() != null) {
            return getData().length;
        }

//        if(data != null){
//            return data.size();
//        }

        return 0;
    }
}

